<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>CAPTCHA</title>
	<script>
	var playTimer = null;
	function clearAudio(parentNode) {
		if(playTimer != null) {
			clearTimeout(playTimer);
		}

		var targetAudio = parentNode.getElementsByTagName('EMBED');
		if (targetAudio != null && targetAudio.length > 0) {
			targetAudio[0].stop();
			parentNode.removeChild(targetAudio[0]);
			return;
		}

		targetAudio = parentNode.getElementsByTagName('AUDIO');
		if (targetAudio != null && targetAudio.length > 0) {
			parentNode.removeChild(targetAudio[0]);
		}
	}

	function playSoundCaptcha() {
		var delay = 4000;
		var playerArea = $('play_audio');
		clearAudio(playerArea);

		var key = $('chptchakey').value;
		var wavURL = "/login/soundcaptcha/soundCaptcha.wav?key=" + key + "&replay=" + new Date().valueOf();
		
		try {
			var audio = new Audio();
			if (!audio.canPlayType('audio/wav')) {
				throw new Error('');
			}

			audio = new Audio(wavURL);
			playTimer = setTimeout(function(){
					playerArea.appendChild(audio);
					audio.play();
				}, delay);
		} catch(e) {
			playTimer = setTimeout(function() {
				var audio = document.createElement('EMBED');
				audio.setAttribute('src', wavURL);
				audio.setAttribute('hidden', true);
				audio.setAttribute('autostart', true);
				audio.setAttribute('showstatusbar', false);
				audio.setAttribute('showcontrols', false);
				audio.setAttribute('showaudiocontrols', false);
				audio.setAttribute('showtracker', false);
				playerArea.appendChild(audio);
			}, delay);
		}
	}


	</script>
</head>
<body>
	<a href="#" id="play_audio" type="text/button" onclick="playSoundCaptcha(); return false;">
		<span>실행</span>
		<EMBED type=audio/x-wav hidden=true src="http://simplecaptcha.sourceforge.net/audio/audio_captcha1.wav" autostart="true" showstatusbar="false" showcontrols="false" showaudiocontrols="false" showtracker="false">
	</a>
	
</body>
</html>